﻿using System;
using FxCore.Stuff;

namespace FxCore.Base
{
    public class LonlatPoint
    {
        public float LonX { get; }

        public float LatY { get; }

        public LonlatPoint()
        {
            this.LonX = 0.0F;
            this.LatY = 0.0F;
        }

        public LonlatPoint(float lonX, float latY)
        {
            this.LonX = lonX;
            this.LatY = latY;
        }

        public static bool operator ==(LonlatPoint pointA, LonlatPoint pointB)
        {
            if (pointA == null || pointB == null)
            {
                throw new NullReferenceException();
            }

            return Helper.CompareFloat(pointA.LonX, pointB.LonX) && Helper.CompareFloat(pointA.LatY, pointB.LatY);
        }

        public static bool operator !=(LonlatPoint pointA, LonlatPoint pointB)
        {
            return !(pointA == pointB);
        }

        public static LonlatPoint operator -(LonlatPoint pointA, LonlatPoint pointB)
        {
            return new LonlatPoint(pointA.LonX - pointB.LonX, pointA.LatY - pointB.LatY);
        }

        public static LonlatPoint operator +(LonlatPoint pointA, LonlatPoint pointB)
        {
            return new LonlatPoint(pointA.LonX + pointB.LonX, pointA.LatY + pointB.LatY);
        }

        public override string ToString()
        {
            return $"经纬度点:{{经度=>{this.LonX}, 维度=>{this.LatY}}}";
        }

        public override bool Equals(object obj)
        {
            LonlatPoint tmp = (LonlatPoint) obj;
            if (tmp == null)
            {
                throw new NullReferenceException();
            }

            return Helper.CompareFloat(tmp.LonX, this.LonX) && Helper.CompareFloat(tmp.LatY, this.LatY);
        }

        public override int GetHashCode()
        {
            return this.LonX.GetHashCode() ^ this.LatY.GetHashCode();
        }
    }
}
